package com.bbs.detai1713.controller;

import com.bbs.detai1713.model.CreateBoard;
import com.bbs.detai1713.model.DeleteBoard;
import com.bbs.detai1713.model.SelectBoard;
import com.bbs.detai1713.model.UpdateBoard;
import com.bbs.detai1713.service.DataService;
import com.bbs.detai1713.tool.ResultInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "版块模块")
@Slf4j
@RestController
public class BoardController {
    @Autowired
    DataService dataService;

    @PostMapping("/createBoard")
    public ResultInfo createBoard(@RequestBody CreateBoard createBoard) {
        log.info("创建板块信息如下:{}", createBoard);
        if (dataService.createBoard(createBoard) >= 1)
            return ResultInfo.success(createBoard.getBoardId(), "创建板块成功!");
        else return ResultInfo.failure("创建板块失败");
    }

    @GetMapping("/selectBoard")
    public ResultInfo selectBoard(@RequestParam(required = false) SelectBoard selectBoard) {
        log.info("查询板块参数为:{}", selectBoard);
        return ResultInfo.success(dataService.selectBoard(selectBoard), "查询板块成功!");

    }

    @PostMapping("/deleteBoard")
    public ResultInfo deleteBoard(@RequestBody DeleteBoard deleteBoard) {
        log.info("删除板块,id为:{}", deleteBoard);
        if (dataService.deleteBoard(deleteBoard) >= 1)
            return ResultInfo.success("删除板块成功");
        else
            return ResultInfo.failure("删除板块失败");
    }

    @PostMapping("/updateBoard")
    public ResultInfo updateBoard(@RequestBody UpdateBoard updateBoard) {
        log.info("更新板块,信息为:{}", updateBoard);
        if (dataService.updateBoard(updateBoard) >= 1)
            return ResultInfo.success("更新板块信息成功");
        else
            return ResultInfo.failure("更新板块信息失败");
    }

}
